package it.softphone.commons.spring.test;


import it.softphone.commons.service.LogAware;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Set;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.commons.lang.NullArgumentException;

/**
 * 
 * @author bsorrentino
 *
 */
public class ServletContextTestAdapter implements ServletContext, LogAware {

	private final java.io.File path;
	
	public ServletContextTestAdapter(java.io.File path) {
		if( null == path ) throw new NullArgumentException("path");
		if( !path.exists() ) throw new IllegalArgumentException( String.format("path [%s] doesn't exist!", path));
		if( !path.isDirectory() ) throw new IllegalArgumentException( String.format("path [%s] is not a folder!", path));
		this.path = path;
	}

	@Override
	public Object getAttribute(String arg0) {
		return null;
	}

	@Override
	public Enumeration<?> getAttributeNames() {
		return null;
	}

	@Override
	public ServletContext getContext(String arg0) {
		return null;
	}

	@Override
	public String getInitParameter(String arg0) {
		return null;
	}

	@Override
	public Enumeration<?> getInitParameterNames() {
		return null;
	}

	@Override
	public int getMajorVersion() {
		return 0;
	}

	@Override
	public String getMimeType(String arg0) {
		return null;
	}

	@Override
	public int getMinorVersion() {
		return 0;
	}

	@Override
	public RequestDispatcher getNamedDispatcher(String arg0) {
		return null;
	}

	@Override
	public String getRealPath(String relativePath) {
		return new java.io.File( path, relativePath ).getAbsolutePath();
	}

	@Override
	public RequestDispatcher getRequestDispatcher(String arg0) {
		return null;
	}

	@Override
	public URL getResource(String arg0) throws MalformedURLException {
		return null;
	}

	@Override
	public InputStream getResourceAsStream(String arg0) {
		return null;
	}

	@Override
	public Set<?> getResourcePaths(String arg0) {
		return null;
	}

	@Override
	public String getServerInfo() {
		return null;
	}

	@Override
	public Servlet getServlet(String arg0) throws ServletException {
		return null;
	}

	@Override
	public String getServletContextName() {
		return null;
	}

	@Override
	public Enumeration<?> getServletNames() {
		return null;
	}

	@Override
	public Enumeration<?> getServlets() {
		return null;
	}

	@Override
	public void log(String msg) {
		logger.info( msg );
	}

	@Override
	public void log(Exception e, String msg) {
		logger.error( msg, e);
	}

	@Override
	public void log(String msg, Throwable e) {
		logger.error( msg, e);
	}

	@Override
	public void removeAttribute(String arg0) {
	}

	@Override
	public void setAttribute(String arg0, Object arg1) {
	}

	@Override
	public String getContextPath() {
		return null;
	}

}
